<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>个人页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/userProfiles.css">
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
</head>
<body>

<div class="tab-pane fade show active">
    <a href="javascript:window.history.go(-1)" class="my-arrow">
        <span><i class="fa fa-chevron-left fa-2x"></i></span>
    </a>
</div>
<br/>
<br/>
<div class="tab-pane fade show active" id="travels">
    <dl class="list" render-loop="list">
        <dd>
            <div class="row">
                <div class="col-2 img">
                    <a href="userProfiles.html" render-key="list.id" render-fun="handle">
                        <img class="rounded-circle" render-src="list.user.headImgUrl">
                    </a>
                </div>
                <div class="col-6 mine">
                    <small>
                        <span class="nickName" render-html="list.user.nickName"></span>
                    </small>
                </div>
            </div>
            <hr>
        </dd>
    </dl>
</div>
<script>

    var id = getParams().id;

    $(function () {

        $.get("/users/" + id + "/fans", {pageSize: 10}, function (data) {
            renderView(data);
            pages = data.pages;
            travels = data.list;
        }, "json");

        // 当屏幕滚动到最底部时执行函数
        $(window).scroll(function () {
            // 判断是否到底部
            if (isEnd()) {
                // 判断是否有下一页
                if (currentPage < pages) {
                    // currentPage +1 , 发送ajax请求获取下一页到游记
                    currentPage++;
                    $.get("/users/" + id + "/fans", {currentPage: currentPage, pageSize: 5}, function (data) {
                        // 返回的数据只有翻页后的数据，没有当前页的数据，直接渲染原来的数据就没有了
                        // 原来的数据+当前的数据
                        $.merge(travels, data.list);
                        renderView({list: travels});
                    }, "json");
                } else {
                    $(document).dialog({
                        type: "notice",
                        infoText: "已经到底部了",
                        autoClose: 2500,
                        position: "bottom"
                    });
                }
            }
        });
    });

    // 给.travels绑定渲染函数
    function renderView(data) {
        $("#travels").renderValues(data, {
            // 属性名就是函数的名称
            handle: function (ele, value) {
                $(ele).attr("href", "/userProfiles.html?id=" + value);
            }
        });
    }
</script>
</body>
</html>